<!--
 * @Author: duan
 * @Description:  double-twelve
 * @Version: 1.0.0
 * @Time: 2020/11/16
-->
<template>
  <div class="goods-details">
    <!--banner-->
    <!--商品详情-->
    <img :src="goodsInfo.productIcon" alt="" class="banner-img">

    <div class="goods-info">
      <div class="content">
        <div class="price">
          <div class="sale-price">¥{{ goodsInfo.salePrice }}</div>
          <div class="market-price">¥{{ goodsInfo.marketPrice }}</div>
        </div>
        <div class="name">
          {{ goodsInfo.productName }}
        </div>
      </div>
    </div>

    <!--商品详情-->
    <div class="details blank" ref="goodsDetail">
      <div class="content-details">
        <div class="title">商品详情</div>
        <div class="product-desc" v-html="goodsInfo.productDesc"></div>
      </div>
      <div class="title"></div>
    </div>

    <!--底部抢购-->
    <div class="footer">
      <div class="pay-amount" v-if="show">¥
        {{ (Number(this.goodsInfo.marketPrice)).toFixed(2) }}
      </div>
      <div class="pay-amount" v-if="!show">¥
        {{ (Number(this.goodsInfo.salePrice)).toFixed(2) }}
      </div>
      <div class="submit" @click="goBuy">立即购买</div>
      <!--气泡窗-->
      <div class="org_box"
           @click="goMember(goodsInfo.equityNo)"
           v-if="show">
        <span class="org_bot_cor"></span>
        开通乐享会员权益包，立减{{ (Number(goodsInfo.marketPrice) - Number(goodsInfo.salePrice)).toFixed(2) }}元
      </div>
    </div>

    <!--返回顶部-->
    <BackToTop/>
  </div>
</template>

<script>
import BackToTop from '@/components/BackToTop'
import {Toast} from 'vant';

export default {
  components: {BackToTop},
  data() {
    return {
      // 商品描述和详情
      goodsInfo: {},
      number: 1,
      discountInfo: [],
      show: false
    }
  },
  // 生命周期 - 创建完成（访问当前this实例）
  created() {
    this.getGoodsDetails() // 获取商品详情
  },
  computed: {
    total: function () {
      return (Number(this.goodsInfo.marketPrice)).toFixed(2)
    }
  },
  // 方法
  methods: {
    // 1丶获取商品详情===================================
    getGoodsDetails() {
      const params = {
        activityProductNo: this.$route.query.activityProductNo
      }
      this.$HttpPost(this.$api.goodsDetails, params).then((res) => {
        if (res.code === '000') {
          this.goodsInfo = res.content
          this.show = false
          // 请求成功调取优惠券接口
          this.$HttpPost(this.$api.discountAmount, params).then(res => {
            if (res.code === '000') {
              this.discountInfo = res.content
              if (this.discountInfo.length === 0) {
                this.show = true
              } else {
                this.show = false
              }
            }
          })
        } else {
          this.$toast(res.desc, 'middle')
          this.goodsInfo = {}
        }
      })
    },
    // 2丶购买下单按钮跳转操作===================================
    goBuy() {
      if (!this.goodsInfo.activityProductNo) {
        return Toast('商品不存在')
      }
      this.$router.push({
        path: '/goods/confirm',
        query: {
          activityProductNo: this.goodsInfo.activityProductNo,
        }
      })
    },
    //跳转到权益购买页面
    goMember(id) {
      this.$router.push({
        path: '/vip',
        query: {
          equityNo: id
        }
      })
    },
  }
}
</script>
<style scoped lang='scss'>

.goods-details {
  padding-bottom: 120px;
  min-height: 100%;
  background-color: #F4F5F7;
  overflow-x: hidden;

  img{
    display: block !important;
  }
  .banner-img {
    width: 100%;
    height: 420px;
    background-color: #FFFFFF;
  }

  //价格
  .goods-info {
    width: 100%;
    box-sizing: border-box;
    margin-top: 28px;
    padding: 0 14px;

    .content {
      display: flex;
      justify-content: space-between;
      align-items: flex-start;
      width: 100%;
      box-sizing: border-box;
      padding: 20px 0 20px 30px;
      background-color: #FFFFFF;
      border-radius: 14px;

      .price {
        width: 200px;
        flex-direction: column;

        .sale-price {
          font-size: 40px;
          font-family: PingFangSC, PingFangSC-Semibold;
          font-weight: 600;
          text-align: left;
          color: #d93939;
        }

        .market-price {
          margin-top: 10px;
          font-size: 26px;
          font-family: PingFangSC, PingFangSC-Light;
          font-weight: 300;
          text-decoration: line-through;
          text-align: left;
          color: #989898;
          text-decoration: line-through;
        }
      }

      .name {
        width: 100%;
        box-sizing: border-box;
        padding: 0 20px;
        font-size: 30px;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        text-align: left;
        color: #000000;
        word-break: break-all;
      }
    }
  }

  .goods-desc {
    display: flex;
    justify-content: space-between;
    flex-direction: column;
    width: 100%;
    height: 100%;
    padding: 32px 23px 22px 23px;
    box-sizing: border-box;
    border-radius: 14px;
    background-color: #ffffff;

    .name {
      align-self: start;
      font-size: 36px;
      font-family: PingFang, PingFang-SC;
      font-weight: 600;
      color: #000000;
      text-align: left;
    }

    .price {
      align-self: flex-end;

      .sale-price {
        font-size: 43px;
        font-family: PingFangSC, PingFangSC-Semibold;
        font-weight: 600;
        color: #d93939;
      }

      .old-price {
        margin-left: 15px;
        font-family: PingFangSC, PingFangSC-Light;
        font-weight: 300;
        color: #989898;
        text-decoration: line-through;
      }
    }

    .start {
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 25px;
      font-family: PingFang, PingFang-SC;
      color: #000000;

      .van-count-down {
        margin-left: 5px;
        font-size: 12px;
        color: #d93939;
      }
    }
  }

  /*购买数量*/
  .blank {
    width: 100%;
    box-sizing: border-box;
    padding: 0 14px;
    margin-top: 26px;

    .content {
      width: 100%;
      height: 100%;
      display: flex;
      justify-content: space-between;
      align-items: center;
      background-color: #ffffff;
      border-radius: 14px;
      box-sizing: border-box;
      padding: 30px 25px;

      .value {
        font-size: 29px;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        color: #3e3e3e;
        letter-spacing: 1px;
      }
    }

    &.details {
      margin-top: 20px;

      .content-details {
        display: flex;
        justify-content: start;
        align-items: start;
        flex-direction: column;
        width: 100%;
        min-height: 600px;
        background-color: #ffffff;
        border-radius: 14px;
        box-sizing: border-box;
        padding: 30px 0;
        margin-bottom: 100px;
        padding-bottom: 50px;
        box-sizing: border-box;
        overflow: hidden;

        .title {
          position: relative;
          margin-left: 40px;
          margin-top: 19px;
          font-size: 29px;
          font-family: PingFangSC, PingFangSC-Regular;
          font-weight: 400;
          color: #3e3e3e;
          text-align: left;
          line-height: 41px;
          letter-spacing: 1px;

          &::after {
            content: '';
            position: absolute;
            left: -20px;
            top: 10px;
            display: block;
            width: 5px;
            height: 23px;
            background: #000000;
          }
        }

        .product-desc {
          width: 100%;
        }
      }

    }
  }

  /*底部立即抢购*/
  .footer {
    position: fixed;
    left: 50%;
    transform: translate(-50%, 0);
    bottom: 60px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 690px;
    height: 90px;
    margin: 0 auto;
    border-radius: 45px;
    //overflow: hidden;

    .pay-amount {
      width: 50%;
      height: 90px;
      background: linear-gradient(92deg, #fcdfdb 2%, #eda897 98%);
      font-size: 36px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 500;
      text-align: center;
      color: #96012b;
      line-height: 90px;
      border-radius: 45px 0 0 45px;

    }

    .submit {
      width: 50%;
      color: #ffffff;
      font-size: 30px;
      font-weight: 500;
      text-align: center;
      background: #B0071E;
      color: #ffffff;
      line-height: 90px;
      border-radius: 0 45px 45px 0;
    }

    //气泡窗
    .org_box {
      position: absolute;
      top: -20px;
      right:15px;
      padding: 5px 15px;
      background: #fdd413;
      font-size: 18px;
      font-family: PingFangSC, PingFangSC-Regular;
      font-weight: 400;
      text-align: center;
      color: #000000;
    }

    .org_bot_cor {
      position: absolute;
      left: 0px;
      bottom: -29px;
      width: 0;
      height: 0;
      font-size: 0;
      border-bottom: 10px solid transparent;
      border-right: 10px solid transparent;
      border-top: 20px solid #fdd413;
      overflow: hidden;
    }
  }


  /*返回头部*/
  .go-top {
    position: fixed;
    right: 30px;
    bottom: 150px;
    width: 62px;
    height: 62px;
    z-index: 99;
  }

}

</style>
